<?php

/* @(#) $Id: sqlcolumn.php 3 2009-02-16 17:58:10Z mo@ilaven.net $ */

abstract class DBOSQLColumn
{
	protected $db;
	
	public $name;
	public $index;
	public $type;
	public $length;
	public $flags;
	public $comment;
	public $dropped;
	public $nativeType;
	public $defaultValue = null;
	
	public function __construct($table, $db, $name, $type, $length = null, $flags = null, $comment = null)
	{
		$this->db = $db;
		$this->name = $name;
		$this->index = DBINDEX_NONE;
		$this->type = $type;
		$this->length = $length;
		$this->flags = $flags;
		$this->comment = $comment;
		$this->dropped = false;
		if($this->type == DBTYPE_ID)
		{
			$this->flags |= DBFLAGS_UNSIGNED;
		}
		if($this->flags & DBFLAGS_INDEX)
		{
			$this->index = DBINDEX_KEY;
		}
		if($this->flags & DBFLAGS_UNIQUE)
		{
			$this->index = DBINDEX_UNIQUE;
		}
		if($this->flags & DBFLAGS_PRIMARY)
		{
			$this->index = DBINDEX_PRIMARY;
		}
		if($this->flags & DBFLAGS_FULLTEXT)
		{
			$this->index = DBINDEX_FULLTEXT;
		}
		if($this->flags & DBFLAGS_NOTNULL)
		{
			switch($type)
			{
				case DBTYPE_INT:
				case DBTYPE_TINYINT:
					$this->defaultValue = 0;
					break;
				case DBTYPE_BOOLEAN:
					$this->defaultValue = 'N';
					break;
			}
		}
		$this->nativeType = $this->getNativeType();
	}
}
